import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Lobster here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Lobster extends Actor
{
    /**
     * Act - do whatever the Lobster wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    int count=0;
    public void act() 
    {
        move(5);
        randomTurn();
        turnAtEdge();
        eat();
        stop();
    }
   
    public void randomTurn(){
        if (Greenfoot.getRandomNumber(100) < 40){
            turn(Greenfoot.getRandomNumber(30) -15);
        
        }
    }
    public void turnAtEdge(){
        if(isAtEdge()){
            turn(75);
        }
    }
 
    public void eat() {
        if (isTouching(Crab.class)) {
            removeTouching(Crab.class);
            Greenfoot.playSound("au.wav");
            count++;
        }
    }

    public void stop() {
        if (count==1) {
            Greenfoot.stop();
            World w = getWorld();
            GreenfootImage bg = w.getBackground();
            Font font = bg.getFont();
            font = font.deriveFont(150);
            bg.setFont(font);
            bg.setColor(Color.RED);
            bg.drawString("失败!",180,280);
        }
    }


}
